package com.yonyougov.devops.cruxcisupport.committrace;

import com.yonyougov.devops.cruxcisupport.committrace.dto.QueryCommitTracePageRequestDto;
import com.yonyougov.devops.cruxcisupport.committrace.vo.CommitTracePageVo;
import com.yonyougov.devops.cruxcisupport.committrace.vo.QueryCommitTracePageDto;
import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.fwc.core.controller.CrudController;
import com.yonyougov.devops.fwc.core.entity.Pagination;
import com.yonyougov.devops.fwc.core.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigInteger;

/**
 * Created by ligson on 2017/8/11.
 */
@Api(tags = "提测追踪模块")
@RestController
@RequestMapping("/api/v2/commitTrace")
public class CommitTraceController extends CrudController<CommitTraceEntity, BigInteger> {

    @Autowired
    private CommitTraceService commitTraceService;

    @Override
    public BaseService<CommitTraceEntity, BigInteger> getService() {
        return commitTraceService;
    }

    //<!--用户自定义代码开始-->

    @ApiOperation(value = "前端提测列表调用", notes = "分页模糊查询提测列表")
    @PostMapping(value = "/ct/page/like")
    public BaseResponseDto findCommitTestPageLike(@RequestBody @Valid QueryCommitTracePageRequestDto request) {
        QueryCommitTracePageDto queryCommitTracePageDto = new QueryCommitTracePageDto();
        BeanUtils.copyProperties(request, queryCommitTracePageDto);

        Pagination<CommitTracePageVo> pagination = commitTraceService.findPageBy(queryCommitTracePageDto);

        BaseResponseDto result = BaseResponseDto.getSuccessInstance();
        result.put("totalCount", pagination.getTotalCount());
        result.put("data", pagination.getDatas());
        return result;
    }

    //<!--用户自定义代码结束-->
}
